package org.eiahe.hr.performance.controller;

import lombok.RequiredArgsConstructor;
import org.ehe.common.core.BaseController;
import org.ehe.common.mybatis.core.page.PageQuery;
import org.eiahe.hr.performance.domain.PerformanceScoreDetail;
import org.eiahe.hr.performance.domain.bo.PerformanceScoreDetailBo;
import org.eiahe.hr.performance.domain.vo.PerformanceScoreDetailVo;
import org.eiahe.hr.performance.service.IPerformanceScoreDetailService;
import org.ehe.common.core.domain.R;
import org.ehe.common.log.annotation.Log;
import org.ehe.common.log.enums.BusinessType;
import org.ehe.common.mybatis.core.page.TableDataInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import cn.dev33.satoken.annotation.SaCheckPermission;

import java.util.List;

/**
 * 绩效评分明细Controller
 *
 * @author zhangnn
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/performance/scoreDetail")
public class PerformanceScoreDetailController extends BaseController {

    private final IPerformanceScoreDetailService performanceScoreDetailService;

    /**
     * 查询绩效评分明细列表
     */
    @SaCheckPermission("performance:scoreDetail:list")
    @GetMapping("/list")
    public TableDataInfo<PerformanceScoreDetailVo> list(PerformanceScoreDetailBo detail, PageQuery pageQuery) {
        return performanceScoreDetailService.queryPageListVo(detail, pageQuery);
    }

    /**
     * 获取绩效评分明细详细信息
     */
    @SaCheckPermission("performance:scoreDetail:query")
    @GetMapping(value = "/{detailId}")
    public R<PerformanceScoreDetailVo> getInfo(@PathVariable("detailId") Long detailId) {
        return R.ok(performanceScoreDetailService.queryById(detailId));
    }

    /**
     * 新增绩效评分明细
     */
    @SaCheckPermission("performance:scoreDetail:add")
    @Log(title = "绩效评分明细", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody PerformanceScoreDetailBo detail) {
        return toAjax(performanceScoreDetailService.insertByBo(detail));
    }

    /**
     * 修改绩效评分明细
     */
    @SaCheckPermission("performance:scoreDetail:edit")
    @Log(title = "绩效评分明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated @RequestBody PerformanceScoreDetailBo detail) {
        return toAjax(performanceScoreDetailService.updateByBo(detail));
    }

    /**
     * 删除绩效评分明细
     */
    @SaCheckPermission("performance:scoreDetail:remove")
    @Log(title = "绩效评分明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{detailIds}")
    public R<Void> remove(@PathVariable Long[] detailIds) {
        return toAjax(performanceScoreDetailService.deleteWithValidByIds(List.of(detailIds), true));
    }

    /**
     * 根据结果ID查询绩效评分明细列表
     */
    @SaCheckPermission("performance:scoreDetail:list")
    @GetMapping("/listByResultId/{resultId}")
    public R<List<PerformanceScoreDetailVo>> listByResultId(@PathVariable Long resultId) {
        List<PerformanceScoreDetailVo> list = performanceScoreDetailService.queryListByResultId(resultId);
        return R.ok(list);
    }

    /**
     * 根据结果ID和评分人查询绩效评分明细列表
     */
    @SaCheckPermission("performance:scoreDetail:list")
    @GetMapping("/listByResultIdAndScorer")
    public R<List<PerformanceScoreDetailVo>> listByResultIdAndScorer(
            @RequestParam Long resultId,
            @RequestParam String scorer) {
        List<PerformanceScoreDetailVo> list = performanceScoreDetailService.queryListByResultIdAndScorer(resultId,
                scorer);
        return R.ok(list);
    }
}